<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../../vue.js"></script>
</head>

<body>
    <div id="app">
        <div :is="com"></div>
        <button @click="changem">点击</button>
    </div>
    <script>
        let comA = {
            template: `<div>
                <h2>我是comA组件</h2>
                <input type='text'></div>`,
        };
        let comB = {
            template: `<div>
                <h2>我是comB组件</h2>
                <input type='text'></div>`,
        };
        new Vue({
            el: "#app",
            components: {
                comA,
                comB,
            },
            data: {
                com: "com-a",
            },
            methods: {
                changem() {
                    if (this.com == 'com-a') {
                        this.com = 'com-b'
                    } else {
                        this.com = 'com-a'
                    }
                }
            }
        });
    </script>
</body>

</html>